package com.xqboss.apps.controller.equipment;

import com.xqboss.apps.dto.equipment.EquipmentBreakDto;
import com.xqboss.apps.dto.equipment.EquipmentIncomeDto;
import com.xqboss.apps.dto.equipment.EquipmentPreUpgradeDto;
import com.xqboss.apps.dto.equipment.EquipmentUpgradeDto;
import com.xqboss.apps.service.equipment.EquipmentUpgradeService;
import com.xqboss.apps.service.sys.ConfigService;
import com.xqboss.apps.vo.equipment.*;
import com.xqboss.common.annotation.RepeatSubmit;
import com.xqboss.common.core.controller.BaseController;
import com.xqboss.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author Administrator
 */
@Api(tags = {"装备升级管理"})
@RestController
@RequestMapping("/apps/equipment")
public class EquipmentUpgradeController extends BaseController {

    @Autowired
    private EquipmentUpgradeService equipmentUpgradeService;
    @Autowired
    private ConfigService configService;

    @ApiOperation("装备预升级")
    @PostMapping("pre-upgrade")
    public R<EquipmentPreUpgradeVo> preUpgrade(@RequestBody @Validated EquipmentPreUpgradeDto dto) {
        EquipmentPreUpgradeVo vo = equipmentUpgradeService.preUpgrade(getUserId(), dto.getUserNftId());
        return R.ok(vo);
    }

    @RepeatSubmit(interval = 1000, justUrl = true)
    @ApiOperation("装备升级")
    @PostMapping("upgrade")
    public R<EquipmentUpgradeVo> upgrade(@RequestBody @Validated EquipmentUpgradeDto dto) throws Exception {
        EquipmentUpgradeVo vo = equipmentUpgradeService.upgrade(getUserId(), dto);
        return R.ok(vo);
    }

    @ApiOperation("收益估算")
    @PostMapping("estimate-income")
    public R<EquipmentIncomeVo> estimateIncome(@RequestBody @Validated EquipmentIncomeDto params) {
        EquipmentIncomeVo vo = equipmentUpgradeService.estimateIncome(getUserId(), params);
        return R.ok(vo);
    }

    @ApiOperation("装备-预突破")
    @PostMapping("pre-break")
    public R<EquipmentPreBreakVo> preBreak(@RequestBody @Validated EquipmentPreUpgradeDto dto) {
        EquipmentPreBreakVo vo = equipmentUpgradeService.preBreak(getUserId(), dto.getUserNftId());
        return R.ok(vo);
    }

    @ApiOperation("装备-预进化")
    @PostMapping("pre-evolve")
    public R<EquipmentPreBreakVo> preEvolve(@RequestBody @Validated EquipmentIncomeDto params) {
        EquipmentPreBreakVo vo = equipmentUpgradeService.preEvolve(getUserId(), params);
        return R.ok(vo);
    }

    @RepeatSubmit(interval = 1000, justUrl = true)
    @ApiOperation("装备-材料突破")
    @PostMapping("break-materials")
    public R<EquipmentBreakVo> breakMaterials(@RequestBody @Validated EquipmentBreakDto dto) throws Exception {
        EquipmentBreakVo vo = equipmentUpgradeService.breakMaterials(getUserId(), dto);
        return R.ok(vo);
    }

    @RepeatSubmit(interval = 1000, justUrl = true)
    @ApiOperation("装备-进化")
    @PostMapping("evolve")
    public R<Map<String, Object>> evolve(@RequestBody @Validated EquipmentIncomeDto dto) throws Exception {
        Map<String, Object> vo = equipmentUpgradeService.evolve(getUserId(), dto);
        return R.ok(vo);
    }

    @ApiOperation("获取打卡系数配置")
    @GetMapping("punch/config")
    public R<EquipmentPunchConfigVo> getPunchConfig(){
        EquipmentPunchConfigVo dto = configService.getPunchConfigByApp();
        return R.ok(dto);
    }

}
